import * as vscode from 'vscode';
import tomcatHotTreeView from './component/TreeView';
import ConfigUtils from './utils/ConfigUtils';
import { tomcatUtils } from './utils/OperationUtils';
import  webView  from './component/webView';
import filtUtils from './utils/fileUtils';
import Command from './utils/Command';
import { MessagebyTime } from './utils/Message';

let message : MessagebyTime| null = null;
async function activate(context: vscode.ExtensionContext) {
	// 相关的对象提供上下文
	ConfigUtils.init(context);
	webView.init(context);
	tomcatHotTreeView.init(context);
	const command = new Command(context);
	filtUtils.init(context);

	// 视图刷新
	tomcatHotTreeView.flush();
	// 命令注册
	let comm = vscode.commands.registerCommand('tomcat-hot.treeCommand', tomcatHotTreeView.command);
	const showProject = vscode.commands.registerCommand('tomcat-hot.showProject', command.showProject);

	const openFile = vscode.commands.registerCommand('tomcat-hot.editTomcat', tomcatHotTreeView.commands.editTomcat);
	let openServerXmlFile = vscode.commands.registerCommand('tomcat-hot.openServerXmlFile', tomcatHotTreeView.commands.openServerXmlFile);
	let tomcat = vscode.commands.registerCommand('tomcat-hot.addTomcat', tomcatHotTreeView.commands.addTomcat);
	let develop = vscode.commands.registerCommand('tomcat-hot.develop', tomcatHotTreeView.commands.addDevelop);
	let editDevelop = vscode.commands.registerCommand('tomcat-hot.editDevelop', tomcatHotTreeView.commands.editDevelop);
	// 对象热加载提示
	let hotcodereplace = vscode.debug.onDidReceiveDebugSessionCustomEvent(async (event) => {
		if(event.event === 'hotcodereplace' && (event.body.changeType ==='STARTING' || event.body.changeType === 'ERROR')){
			message?.close();
			message = new MessagebyTime("热加载提示: ",event.body.changeType ==='STARTING' ? '热替换成功' : '热替换失败！！！！');
		}
	    console.log(event);
	});

	vscode.commands.executeCommand("JavaDebug.PickJavaProcess").then((data)=>{
		console.log(data);
	});
	// 打开住配置文件
	let treeView = vscode.window.registerTreeDataProvider('my-ts-custom-view', tomcatHotTreeView.treeview );

	vscode.window.createTreeView('my-ts-custom-view', {treeDataProvider: tomcatHotTreeView.treeview});
	context.subscriptions.push(treeView, comm, tomcatUtils.startDebugEvent, tomcatUtils.stopDebugEvent, showProject, openFile, hotcodereplace, openServerXmlFile, tomcat, develop, editDevelop);
	
}
function deactivate() {} 

export { deactivate, activate };

